<template>
  <div class="infoWindow">
    <div class="header-content">
      <div>设置圆形</div>
      <el-icon class="header-close" @click="handleClose"><ep-Close /></el-icon>
    </div>
    <div class="main-content">
      <el-form label-position="right">
        <el-form-item label="半径:" prop="radius">
          <div class="flex align-center" style="width: 100%">
            <el-input-number
              v-model="currentRadius"
              :min="1"
              :step="1"
              step-strictly
              controls-position="right"
              style="flex: 1; margin-right: 5px"
            />
            米
          </div>
        </el-form-item>
      </el-form>

      <div class="bottom-btn">
        <el-button type="primary" round @click="handleSetRadius">确定</el-button>
      </div>
    </div>

    <div class="arrows"></div>
  </div>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'

const emit = defineEmits<{
  (e: 'setRadius', radius: number): void
  (e: 'close'): void
}>()

const props = defineProps<{
  radius: number
}>()

const currentRadius = ref<number>(null)

watch(
  () => props.radius,
  val => {
    currentRadius.value = val
  }
)

const handleClose = () => {
  emit('close')
}

const handleSetRadius = () => {
  if (!currentRadius.value) {
    ElMessage.error('半径不能为空！')
    return
  }
  emit('setRadius', currentRadius.value)
  handleClose()
}
</script>
<style lang="scss" scoped>
.infoWindow {
  position: relative;
  width: 260px;
  border-radius: 6px;
  padding: 10px;
  box-sizing: border-box;
  box-shadow: 0 3px 12px 0 rgba(32, 40, 74, 0.3);
  background: var(--el-bg-color-overlay);
  font-size: 12px;
  .header-content {
    display: flex;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--el-border-color);
    box-sizing: border-box;
  }
  .header-close {
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 10px;
  }

  .main-content {
    padding-top: 10px;
    .label {
      font-weight: 600;
    }
  }
}
:deep(.el-col-24) {
  margin-bottom: 5px;
}

.bottom-btn {
  margin-top: 15px;
  display: flex;
  justify-content: center;
  .el-button {
    width: 155px;
  }
}

.arrows {
  width: 0;
  height: 0;
  border: 5px solid transparent;
  border-left-width: 8px;
  border-right-width: 8px;
  border-top-width: 10px;
  border-top-color: var(--el-bg-color-overlay);
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
}
</style>
